print("Дорогой пользователь, ввведите число:")
abcd = int(input())
if abcd <= 9999 and abcd >= 1000:

    a = abcd // 1000
    b = abcd // 100 % 10
    c = abcd // 10 % 10
    d = abcd % 10

    ab = abcd // 100
    bc = abcd % 1000 // 10
    cd = abcd % 100

    abc = abcd // 10
    bcd = abcd - a * 1000

    n1 = a
    n2 = b
    n3 = c
    n4 = d
    n5 = ab
    n6 = bc
    n7 = cd
    n8 = abc
    n9 = bcd
    n10 = abcd

    for i in range(2, n1 // 2 + 1):  #a
        o = n1 % i
        if o == 0:
             n1 = 0
        else:
            i += 1
    for i in range (2, n2//2+1): #b
        o = n2 % i
        if o == 0:
             n2 = 0
        else:
            i += 1
    for i in range(2, n3 // 2 + 1):  #c
        o = n3 % i
        if o == 0:
            n3 = 0
        else:
            i += 1
    for i in range (2, n4//2+1): #d
        o = n4 % i
        if o == 0:
            n4 = 0
        else:
            i += 1
    for i in range(2, n5 // 2 + 1):  #ab
        o = n5 % i
        if o == 0:
            n5 = 0
        else:
            i += 1
    for i in range (2, n6//2+1): #bc
        o = n6 % i
        if o == 0:
            n6 = 0
        else:
            i += 1
    for i in range(2, n7 // 2 + 1):  #cd
        o = n7 % i
        if o == 0:
            n7 = 0
        else:
            i += 1
    for i in range (2, n8//2+1): #abc
        o = n8 % i
        if o == 0:
            n8 = 0
        else:
             i += 1
    for i in range(2, n9 // 2 + 1):  #bcd
        o = n9 % i
        if o == 0:
           n9 = 0
        else:
            i += 1
    for i in range (2, n10//2+1): #abcd
        o = n10 % i
        if o == 0:
            n10 = 0
        else:
            i += 1

    print(max(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10))
else:
     print("0")